#pragma once

#include "Serializable.h"
#include "LeagueSettings.h"
#include "Vectors.h"

#include "StlStringAndStreams.h"

#include <cassert>

class ServiceProvider;

struct LeagueLayerSettings : public Serializable
{
	bool						isVisible;
	size_t						numOfLeagues;
	STL::vector<STL::string>	leagueNames;
	size_t						numOfPromoted;	
	size_t						numOfDemotioned;	
	size_t						layerIndex;	
	LeagueSettings				leagueSettings;

	LeagueLayerSettings()
		: isVisible(false)
		, numOfLeagues(0)
		, numOfDemotioned(0)
		, layerIndex(0)
	{
	}

	virtual	ZStream& Serialize(ZStream& o_stream) const;
	virtual ZStream& Deserialize(ZStream& i_stream);

};
typedef	STL::vector<LeagueLayerSettings>		LMSettingsContainer;
typedef LMSettingsContainer::iterator			LMSettingsIterator;
typedef LMSettingsContainer::const_iterator		LMSettingsCIterator;

class LeagueLayer
{
public:
	// CTOR & DTOR
	explicit LeagueLayer(ServiceProvider* i_sp);
	~LeagueLayer();

	// FUNCTIONS
	void						Clear();
	void						Update(const bool i_doNotPrompt);
	void						Initialize(const LeagueLayerSettings& i_settings);
	size_t						MaxTurnsOfSeason();
	void						PromoteAndDemote(LeagueLayer* i_lowerLayer, const bool i_doNotPrompt, STD::stringstream& o_message);
	LeagueVec&					GetLeagues();
	const size_t				GetNumOfLeagues() const;
	const size_t				GetTeamsForLeague() const;
	void						EndSeasonUpdate(const bool i_doNotPrompt, STD::stringstream& o_message);
	bool						IsVisible() const;
	const LeagueLayerSettings&	GetSettings() const;
	size_t						GetDemotionsForLeague() const;

private:
	LeagueVec				m_leagues;
	LeagueLayerSettings		m_settings;
	ServiceProvider*		m_sp;
};

inline size_t LeagueLayer::MaxTurnsOfSeason()
{
	return (m_settings.leagueSettings.numOfTeams * 2 - 2);
}

inline LeagueVec& LeagueLayer::GetLeagues()
{
	return m_leagues;
}

inline const size_t LeagueLayer::GetNumOfLeagues() const
{
	return m_settings.numOfLeagues;
}

inline const size_t LeagueLayer::GetTeamsForLeague() const
{
	return m_settings.leagueSettings.numOfTeams;
}

inline bool LeagueLayer::IsVisible() const
{
	return m_settings.isVisible;
}

inline const LeagueLayerSettings& LeagueLayer::GetSettings() const
{
	return m_settings;
}

inline size_t LeagueLayer::GetDemotionsForLeague() const
{
	return m_settings.numOfDemotioned / m_leagues.size();
}
